﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL = Auto.Data.BusMan.BLL;
using Model = Auto.Data.BusMan.Model;

namespace Auto.BusMan.AddForm
{
    public partial class fmCarAddFormWithPic : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }
        }

        private void InitPage()
        {
            string busid = Request.QueryString["BusID"];
            BindData(busid);
        }

        private void BindData(string busid)
        {
            BLL.BusList bl = new BLL.BusList();
            Model.BusList model = bl.GetModel(busid);

            this.lblCompanyName.Text = model.CompanyName;
            //this.lblOdometerBus.Text = model.OdometerBus.ToString();
            this.lblBusIdentificationNO.Text = model.BusIdentificationNO;
            this.lblBusSpec.Text = model.BusSpec;
            this.lblBusBrand.Text = model.BusBrand;
            //this.lblManufacturerID.Text = model.ManufacturerID;
            this.lblManufacturerName.Text = model.ManufacturerName;
            this.lblDeliveryCapacity.Text = model.DeliveryCapacity.ToString();
            this.lblSeatings.Text = model.Seatings.ToString();
            this.lblUseDivName.InitControl(model.CompanyID, model.UseDivID);//.Text = model.UseDivID;
            this.lblUsedFor.Text = model.UsedFor;
            this.lblStatusOfCapital.Text = model.StatusOfCapital;
            this.lblBusConditions.Text = model.BusConditions;
            //this.chkWithBucket.Checked = model.WithBucket;
            this.lblNote.Text = model.Note;
            this.lblPrice.Text = model.Price.ToString();
            this.ucInvoiceFileShow.FileList = model.Invoice;// this.lblInvoice.Text = model.Invoice;
            this.lblExFactoryDate.Text = model.ExFactoryDate.ToString("yyyy-MM-dd");
            this.lblBuyDate.Text = model.BuyDate.ToString("yyyy-MM-dd");
            this.ucBusAppearanceFileShow.FileList = model.BusAppearance;// this.lblBusAppearance.Text = model.BusAppearance;
            this.ucBusLicenseFileShow.FileList = model.BusLicence;// this.lblBusLicence.Text = model.BusLicence;
            this.ucBusCertificateRegistryFileShow.FileList = model.BusCertificateRegistry;// this.lblBusCertificateRegistry.Text = model.BusCertificateRegistry;
            this.ucOperationCertificateFileShow.FileList = model.OperationCertificate;// this.lblOperationCertificate.Text = model.OperationCertificate;
            this.lblInsuranceCompany.Text = model.InsuranceCompany;
            this.lblAnnualVerificationDate.Text = model.AnnualVerificationDate.ToString("yyyy-MM-dd");
            this.lblAnnualVerificationCycle.Text = model.AnnualVerificationCycle.ToString();
            this.lblInsuranceDate.Text = model.InsuranceDate.ToString("yyyy-MM-dd");
            this.lblInsuranceCycle.Text = model.InsuranceCycle.ToString();
            this.lblOperationCeriticateDate.Text = GetDateString(model.OperationCeriticateDate);
            this.lblOperationCeriticateCycle.Text = model.OperationCeriticateCycle.ToString();
            this.lblExtinguisher.Text = model.Extinguisher.ToString();
            this.lblExtinguisherProductionDate.Text = GetDateString(model.ExtinguisherProductionDate);
            this.lblExtinguisherLifecycle.Text = model.ExtinguisherLifecycle.ToString();
            this.lblJack.Text = model.Jack.ToString();
            this.lblJackProductionDate.Text = GetDateString(model.JackProductionDate);
            this.lblWarningBoard.Text = model.WarningBoard.ToString();
            this.lblManual.Text = model.Manual.ToString();
            this.lblBusTransfer.Text = model.BusTransfer;
            this.lblBusKey.Text = model.BusKey.ToString();
            //this.lblCigaretteLighter.Text = model.CigaretteLighter.ToString();
            //this.lblSpareTyre.Text = model.SpareTyre.ToString();
            //this.lblTools.Text = model.Tools.ToString();
            //this.lblAttachNote.Text = model.AttachNote;

        }

        private string GetDateString(DateTime? datetime)
        {
            string str = string.Empty;
            if (datetime != null && datetime != DateTime.MinValue)
            {
                str = Convert.ToDateTime(datetime).ToString("yyyy-MM-dd");
            }
            return str;
        }
    }
}